package com.nondo.rdp.auth.repository;

import com.nondo.rdp.auth.domain.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 岗位DAO接口
 *
 * @author slacrey
 * @version 2013-05-15
 */
public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificationExecutor<Role> {

    @Query("from Role where name = ?1 and delFlag = '" + Role.DEL_FLAG_NORMAL + "'")
    Role findByName(String name);

    @Query("from Role where enname = ?1 and delFlag = '" + Role.DEL_FLAG_NORMAL + "'")
    Role findByEnnameEquals(String enname);

    @Modifying
    @Query("update Role set delFlag='" + Role.DEL_FLAG_DELETE + "' where id = ?1")
    int deleteById(Long id);

}